package maven.demo4;

import java.util.Scanner;

public class TestCar {
    public static void main(String[] args) {
        // java.util.Scanner 是 Java5 的新特征，我们可以通过 Scanner 类来获取用户的输入。
        Scanner input = new Scanner(System.in);
        int rentNum = 0; // 租车数量
        int rentDay = 0; // 租车天数
        // 初始化车辆列表
        Car cars[] = new Car[6];
        cars[0] = new Auto(1, "奥迪A4", 4, 500);
        cars[1] = new Auto(2, "马自达6", 4, 400);
        cars[2] = new Van(3, "皮卡雪6", 4, 2, 450);
        cars[3] = new Auto(4, "金龙", 20, 800);
        cars[4] = new Trunk(5, "松花江", 4, 400);
        cars[5] = new Trunk(6, "依维柯", 20, 1000);

        cars[0].getName();
        System.out.println("您好，欢迎使用哒哒租车系统");
        while (true) {
            System.out.println("请选择：租车服务输入1，退出系统输入2");
            int a = input.nextInt();
            if (a == 2) {
                System.out.println("谢谢使用，再见！");
                break;
            } else if (a == 1) {
                System.out.println("以下是租车列表：");
                System.out.println("编 号" + "\t类型" +"\t容量" + "\t\t日租金/天");
                for(Car each:cars) {
                    System.out.println(each);
                }
                System.out.println("请输入您要租车的数量");
                rentNum = input.nextInt();
                Car rentCar[] = new Car[rentNum];
                int price = 0;
                int totalPerson = 0;
                int totalLoads = 0;

                for(int i = 0;i < rentNum;i++) {
                    while(true) {
                        System.out.println("请输入第" + (i + 1) + "辆车的编号：");
                        int b = input.nextInt();
                        if (b > 6 || b < 0) {
                            System.out.println("输入有误");
                        } else {
                            rentCar[i] = cars[b-1];
                            break;
                        }
                    }
                }

                for(int i = 0;i < rentNum;i++) {
                    totalPerson = totalPerson + rentCar[i].person;
                    totalLoads = totalLoads + rentCar[i].loads;
                }

                System.out.println("请输入租车天数");
                rentDay = input.nextInt();
                for(int i = 0; i < rentNum; i++) {
                    price = price + rentCar[i].rent * rentDay;
                }
                System.out.println("您的账单如下：");
                System.out.println("***可载人的车有：");
                for(int i = 0; i < rentNum; i++) {
                    if(rentCar[i].person != 0) {
                        System.out.println(rentCar[i].name);
                    }
                }
                System.out.println("共可载货" + totalLoads + "吨");
                System.out.println("***租车总价格：" + price + "元");
                System.out.println("感谢惠顾，欢迎下次光临");
                break;
            } else {
                System.out.println("输入有误，请重新输入");
            }
        }
        input.close();
    }
}
